//
//  BottomActionView.m
//  YouinRTCDemo
//
//  Created by 潘欣 on 2023/11/14.
//

#import "BottomActionView.h"
#import <LSTPopView.h>
@interface BottomActionView ()
//@property (nonatomic,weak) LSTPopView *popView;
@end
@implementation BottomActionView

- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {

        self.backgroundColor = rgba(37, 37, 37, 1);
        
        UIButton *endBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [endBtn setTitle:@"结束直播" forState:UIControlStateNormal];
        [endBtn setTitleColor:rgba(255, 0, 0, 1) forState:UIControlStateNormal];
        endBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [endBtn addTarget:self action:@selector(endBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        endBtn.tag = 100;
        [endBtn setBackgroundImage:[UIImage imageNamed:@"jieshuzhibo"] forState:UIControlStateNormal];
        [self addSubview:endBtn];
        [endBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.offset(80);
            make.height.offset(32);
            make.left.mas_equalTo(self.mas_left).offset(68);
            make.top.mas_equalTo(self).offset(16);
        }];
        
        UIButton *leaveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [leaveBtn setTitle:@"离开直播" forState:UIControlStateNormal];
        [leaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        leaveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [leaveBtn addTarget:self action:@selector(endBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        leaveBtn.tag = 101;
        [leaveBtn setBackgroundImage:[UIImage imageNamed:@"leavezhibo"] forState:UIControlStateNormal];
        [self addSubview:leaveBtn];
        [leaveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.offset(80);
            make.height.offset(32);
            make.left.mas_equalTo(endBtn.mas_right).offset(-6);
            make.top.mas_equalTo(self).offset(16);
        }];
        
        NSArray *imgsArr = @[@"kaimai.jpg",@"meiyan_s",@"camera_img"];
        for (int i = 0; i <imgsArr.count; i ++) {
            UIButton *actionsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [actionsBtn addTarget:self action:@selector(actionsBtnAction:) forControlEvents:UIControlEventTouchUpInside];
            actionsBtn.tag = 200+i;
            [actionsBtn setImage:[UIImage imageNamed:imgsArr[i]] forState:UIControlStateNormal];
            if(actionsBtn.tag == 200){
                [actionsBtn setImage:[UIImage imageNamed:@"bimai.jpg"] forState:UIControlStateSelected];
            }
            if(actionsBtn.tag == 201){
                [actionsBtn setImage:[UIImage imageNamed:@"meiyan_img"] forState:UIControlStateSelected];
            }
            
            [self addSubview:actionsBtn];
            [actionsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.offset(40);
                make.height.offset(40);
                make.right.mas_equalTo(self.mas_right).offset(-56*i-20);
                make.top.mas_equalTo(self).offset(12);
            }];
        }
    }
    return self;
}

- (void)endBtnAction:(UIButton *)sender
{
    if([self.delegate respondsToSelector:@selector(bottomActionWithTag:)]){
        [self.delegate bottomActionWithTag:sender.tag];
    }
}

- (void)actionsBtnAction:(UIButton *)sender
{
//    [self.popView dismiss];
    if([self.delegate respondsToSelector:@selector(bottomVideoActions:withButton:)]){
        [self.delegate bottomVideoActions:sender.tag withButton:sender];
    }
}
//
//-(void)show
//{
//    LSTPopView *popView = [LSTPopView initWithCustomView:self
//                                                popStyle:LSTPopStyleSmoothFromBottom
//                                            dismissStyle:LSTDismissStyleSmoothToBottom];
//
//    popView.hemStyle = LSTHemStyleBottom;
//    popView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
//    LSTPopViewWK(popView)
//    popView.popDuration = 0.5;
//    popView.dismissDuration = 0.5;
//    popView.isClickFeedback = YES;
////    popView.rectCorners = UIRectCornerTopLeft | UIRectCornerTopRight;
////    popView.cornerRadius = 15;
//    popView.sweepStyle = LSTSweepStyleY_Positive;
//    popView.dragStyle = LSTDragStyleY_Positive;
//    popView.sweepDismissStyle = LSTSweepDismissStyleSmooth;
//    popView.bgClickBlock = ^{
//        NSLog(@"点击了背景");
//        [wk_popView dismiss];
//    };
//    self.popView = popView;
//
//    [popView pop];
//}
//-(void)dealloc
//{
//    NSLog(@"dealloc");
//}

@end
